//
//  ViewController.m
//  27-ArrayDataSource
//
//  Created by Snow on 16/8/19.
//  Copyright © 2016年 Snow. All rights reserved.
//

#import "ViewController.h"
#import "ArrayDataSource.h"
#define kReuse @"cell"
#define kColor [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1]
@interface ViewController ()<UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *namearray;
@property (nonatomic, strong) ArrayDataSource *arrayDataSource;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self handleData];
    //让arraydataSource替代viewController的数据源工作
    _arrayDataSource = [ArrayDataSource arrayDataSourceinitWithtableViewCellReuse:kReuse arrayDataSource:_namearray configCell:^(UITableViewCell * _Nonnull cell, NSString * _Nonnull model) {
        cell.textLabel.text = model;
    }];
    _tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];
    [self.view addSubview:_tableView];
    _tableView.delegate = self;
    //tableview的数据源变更为自定义的类
    //所有的协议不一定指向self
    _tableView.dataSource = _arrayDataSource;
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kReuse];
}
- (void)handleData
{
    _namearray = @[@"赵五一", @"张合尉", @"高雅馨", @"符淋淋", @"孙遥", @"李毅然", @"于瀚", @"沙长健", @"卢思彤", @"徐昊", @"曹冠雄", @"陈丹明", @"罗浩", @"肖扬", @"王道林", @"宫雪", @"李成", @"冀永金", @"姜浩", @"罗鹏飞", @"李昊林", @"郭宝", @"马峰", @"刘坦奇", @"殷明静", @"邓凯", @"徐康", @"王鍠", @"韩旭", @"杨睿", @"张信宝", @"姜程程", @"包铭礼", @"杜江", @"苗钧豪", @"黄天宇"];
}
//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
//{
//    return _namearray.count;
//}
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kReuse];
//    cell.textLabel.text =  [_namearray objectAtIndex:indexPath.row];
//    cell.backgroundColor = kColor;
//    return cell;
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
